<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>我的报价列表</title>


    <!-- Expand styles -->
    <link href="../css/app/app.css" rel="stylesheet">
    <link href="../css/app/default.css" rel="stylesheet">
    <link href="../css/mui/mui.css" rel="stylesheet">
    <link href="../css/mui/mui.picker.min.css" rel="stylesheet">
	<link href="../css/mui/mui.poppicker.css" rel="stylesheet">

</head>

<body>
    <div>
        <div class="widget-default margin-b-5">
            <div class="farming-tab">
                <div id="segmentedControl" class="mui-segmented-control">
                    <a class="mui-control-item mui-active" quoteStatus="2">报价进行中</a>
                    <a class="mui-control-item" quoteStatus="1">报价已选中</a>
                    <a class="mui-control-item" quoteStatus="3">报价未选中</a>
                </div>
            </div>
        </div>
        <!-- 内容 -->
        <div id="refreshContainer" class="mui-content mui-scroll-wrapper" style="margin-top: 60px;">
            <div class="mui-scroll">
                <div id="list">
                </div>
            </div>
        </div>
    </div>
    <div id="sheet1" class="mui-popover mui-popover-bottom mui-popover-action ">
        <!-- 可选择菜单 -->
        <ul class="mui-table-view">
            <li class="mui-table-view-cell" onclick="callPhone()">
                <a href="#">拨打 <yang id="connectPhone"></yang></a>
            </li>
        </ul>
        <!-- 取消菜单 -->
        <ul class="mui-table-view">
            <li class="mui-table-view-cell">
                <a href="#sheet1"><b>取消</b></a>
            </li>
        </ul>
    </div>
        <script src="../js/dsbridge.js"></script>
        <script src="../js/jquery.js"></script>
        <script src="../js/mui/mui.js"></script>
        <script src="../js/mui/mui.picker.min.js"></script>
        <script src="../js/mui/mui.poppicker.js"></script>
        <script src="../js/layer.js"></script>
        <script src="../js/app/app-base.js"></script>
        <script src="../js/app/app-url.js"></script>
        <script src="../js/app/app-ajax.js"></script>
        <script>
            var page = 1;
            var limit = 10;
            var index = 0;
            var all_data = new Array();
            var userAccId = getUserId();
            //1-已选中 2-进行中 3-未选中 默认=2
            var quoteStatus = 2;

            // 下拉刷新
            function pullDown() {
                page = 1;
                getData();
            }

            // 上拉加载
            function pullUp() {
                page++;
                getData();
            }

            $(function () {
                ready();
            });

            function ready() {
                mui.init({
                    pullRefresh: {
                        container: "#refreshContainer",
                        down: {
                            auto: true,
                            callback: pullDown
                        },
                        up: {
                            contentrefresh: '正在加载...',
                            callback: pullUp
                        }
                    }
                });

                dsBridge.register('refresh', function () {
                    pullDown();
                })
            }

             //类型切换
            mui("#segmentedControl").on('tap', '.mui-control-item', function () {
                quoteStatus = $(this).attr("quoteStatus");
                pullDown();
            });

            // 获取数据
            function getData() {
                var data = {
                    page: page,
                    limit: limit,
                    userAccId: userAccId,
                    quoteStatus: quoteStatus
                }
                getServerData(url_getMyQuotationList, data);
            }

            function changeStatus(whichStatus) {
                quoteStatus = whichStatus;
                pullDown();
            }

            // 接口调用返回
            function getServerDataSuccess(url, body, tag) {
                switch (url) {
                    case url_getMyQuotationList:
                        var data = body.data;
                        if (page == 1) {
                            index = 0;
                            all_data.length = 0;
                        }
                        var h5 = '';
                        for (var i = 0; i < data.length; i++) {
                            all_data.push(data[i]);
                            h5 += '<div class="margin-b-10">'
                                    + '<div class="widget-body widget-default margin-b-1">'
                                        + '<div class="display-flex align-items-center margin-b-10">'
                                            + '<span class="px-content font-15 tuli-bg-b elli1">'+data[i].tranTypeName+'</span><p class="black1 font-16 font-weight no-margin elli1 padding-r-10">'+ data[i].title+'</p>'
                                        + '</div>'
                                        + '<div class="display-flex align-items-center justify-content-between padding-t-5">'
                                            + '<p class="font-12 gray no-margin">主办方：'+data[i].tranSponsors+'</p><span class="font-16 font-weight red">￥'+data[i].budgetShow+'</span>'
                                        + '</div>'
                                        + '<div class="display-flex align-items-center justify-content-between">'
                                            + '<p class="font-12 gray no-margin">培训地址：'+data[i].tranAddressShow+'</p><span class="font-12 gray">'+data[i].quoteNum+'人已报价</span>'
                                        + '</div>'
                                    + '</div>'
                                    + '<div class="text-right padding-10-15 widget-default quoteInfo" dId="'+index+'">';
                                        if(quoteStatus == 1){
                                            h5 += '<span class="tuli-content2 font-13 tuli-bg-b contactDemand">联系需求方</span>';
                                        }
                                    h5+=  '<span class="tuli-content2 font-13 quoteDetail">我的报价</span>'
                                        + '<span class="tuli-content2 font-13 demandDetail">查看详情</span>'
                                    + '</div>'
                                + '</div>';
                            index++;
                        }
                        if (page == 1) {
                            mui('#refreshContainer').pullRefresh().endPulldownToRefresh();
                            if (data.length > 0) {
                                mui('#refreshContainer').pullRefresh().refresh(true);
                            }
                            $("#list").html(h5);
                        } else {
                            $("#list").append(h5);
                            mui('#refreshContainer').pullRefresh().endPullupToRefresh(data.length != limit);
                        }
                        break;
                    default:
                        break;
                }
            }

            function getServerDataFailed(url, data) {
                mui('#refreshContainer').pullRefresh().endPulldownToRefresh();
                mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
            }

            //报价详情
            mui("#list").on('tap', '.quoteDetail', function () {
                var detailIndex = $(this).parents(".quoteInfo").attr("dId");
                localStorage.setItem("view-quote-id", all_data[detailIndex].quotationId);
                dsBridge.call("quoteDetail","");
            });

            //需求详情
            mui("#list").on('tap', '.demandDetail', function () {
                var detailIndex = $(this).parents(".quoteInfo").attr("dId");
                localStorage.setItem("tranDemand_Id", all_data[detailIndex].id);
                localStorage.setItem("tranDemandDetail_sourceType", 'my-quote');
                dsBridge.call("demandDetail","");
            });

            //联系需求方
            mui("#list").on('tap', '.contactDemand', function () {
                var detailIndex = $(this).parents(".quoteInfo").attr("dId");
                var connectPhone = all_data[detailIndex].connectPhone;
                $("#connectPhone").html(connectPhone);
                mui('#sheet1').popover('toggle');
            });

            //拨打电话
            function callPhone(){
                dsBridge.call("callPhone", $("#connectPhone").text());
                mui('#sheet1').popover('toggle');
            }
        </script>
</body>

</html>